package com.shiftychess.board
{
	public class Position
	{
		private static var allPositions:Array;
		
		private var _x:String;
		private var _y:int;
		
		public function Position() {
		}
		
		public function set x(value:String):void {
			_x = value;
		}
		
		public function get x():String {
			return _x;
		}
		
		public function set y(value:int):void {
			_y = value;
		}
		
		public function get y():int {
			return _y;
		}
		
		public static function convertXtoInt(value:String):int {
			switch(value) {
				case "A":
					return 1;
				case "B":
					return 2;
				case "C":
					return 3;
				case "D":
					return 4;
				case "E":
					return 5;
				case "F":
					return 6;
				case "G":
					return 7;
				case "H":
					return 8;
				default:
					return -1;
			}
		}
		
		public static function convertIntToX(value:int):String {
			switch(value) {
				case 1:
					return "A";
				case 2:
					return "B";
				case 3:
					return "C";
				case 4:
					return "D";
				case 5:
					return "E";
				case 6:
					return "F";
				case 7:
					return "G";
				case 8:
					return "H";
				default:
					return null;
			}
		}
		
		public static function getAllPositions():Array {
			if(allPositions == null) {
				allPositions = new Array();
				var pos:Position;
				
				for(var i:int = 1; i < 9; i++) {
					pos = new Position();
					pos.x = "A";
					pos.y =	i;
					allPositions.push(pos);
	
					pos = new Position();
					pos.x = "B";
					pos.y =	i;
					allPositions.push(pos);
					
					pos = new Position();
					pos.x = "C";
					pos.y =	i;
					allPositions.push(pos);	

					pos = new Position();
					pos.x = "D";
					pos.y =	i;
					allPositions.push(pos);	

					pos = new Position();
					pos.x = "E";
					pos.y =	i;
					allPositions.push(pos);
	
					pos = new Position();
					pos.x = "F";
					pos.y =	i;
					allPositions.push(pos);
					
					pos = new Position();
					pos.x = "G";
					pos.y =	i;
					allPositions.push(pos);	

					pos = new Position();
					pos.x = "H";
					pos.y =	i;
					allPositions.push(pos);
				}
			}
			
			return allPositions;
		}
	}
}